package com.java.huxb.rabbitmq.demo.demoexpire.basedemo;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author huxb
 * @date 2020/2/1 0001 下午 2:59
 */
public class Producer {
    public static void main(String[] args) throws IOException, TimeoutException {
        // 创建连接工厂, 初始化配置
        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setHost("119.27.175.48");
        connectionFactory.setPort(5672);
        connectionFactory.setVirtualHost("/");
        // 通过链接工程获取链接
        Connection connection = connectionFactory.newConnection();
        // 通过connection 获取Channel
        Channel channel =  connection.createChannel();
        // 通过 channel 发送数据

        for (int i = 0; i < 5; i++) {
            String msg = "hello rabbitMq" + i;
            // 不指定exchange则默认走 AMQP exchange
            channel.basicPublish("", "test001", null, msg.getBytes());
        }
        //关闭链接
        channel.close();
        connection.close();
    }
}
